package com.yrj.shopping;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
    private static final List<Product> Products = new ArrayList<>();
    static {
        Products.add(new Product("饮品","雪碧",3.0,10));
        Products.add(new Product("饮品","可乐",3.0,10));
        Products.add(new Product("速食","速冻水饺",13.0,15));
        Products.add(new Product("速食","泡面",3.5,20));
        Products.add(new Product("零食","果冻",4.5,20));
        Products.add(new Product("零食","辣条",1.5,10));
        Products.add(new Product("水果","红柚",3.7,15));
        Products.add(new Product("水果","丑橘",2.4,25));
        Products.add(new Product("熟食","鸡肉卷",5.0,5));
        Products.add(new Product("熟食","淀粉肠",3.0,5));
    }


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        ShoppingCart shoppingCart = new ShoppingCart();
        System.out.println("欢迎光临电子商店，Java小工竭诚为您服务");
        boolean flag = false;
        System.out.println("您想进行什么操作呢？");
        System.out.println("1. 查看商品种类");
        System.out.println("2. 添加该商品到购物车");
        System.out.println("3. 查看我的购物车");
        System.out.println("4. 取消购物车中的商品");
        System.out.println("5. 结算购物车");
        while(!flag) {

            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    System.out.println("我们有以下几种商品类型供您挑选");
                    Product.productSort();
                    System.out.println("我们有以下商品供您挑选");
                    for (Product p : Products) {
                        System.out.println("名称：" + p.getName() + ", 种类：" + p.getSort() + ", 价格：" + p.getPrice() + ", 数量：" + p.getNum());
                    }
                    break;
                case 2:
                    System.out.println("请选择您想要购买的商品：");
                    String productName = scanner.next();
                    Product productToAdd = null;
                    for (Product p : Products) {
                        if (p.getName().equals(productName)) {
                            productToAdd = p;
                            break;
                        }
                    }
                    if (productToAdd == null) {
                        System.out.println("该商品不存在！");
                        break;
                    }
                    System.out.println("您想要几件该商品呢？请输入：");
                    int num = scanner.nextInt();
                    ShoppingCart.addProduct(productToAdd,num);
                    break;
                case 3:
                    ShoppingCart.viewCart();
                    break;
                case 4:
                    System.out.println("您想要把哪一件商品删除呢》请输入该商品名称：");
                    String productToRemove = scanner.next();
                    ShoppingCart.removeProduct(productToRemove);
                    break;
                case 5:
                    ShoppingCart.checkout();
                    flag = true;
                    break;
                default:
                    System.out.println("输入错误，没有该操作选项，请重新输入哦");
            }
        }
        scanner.close();
    }
}

